<template>
	<view>
		<view  @click="openShare()">开始共享</view>
		<video id="video" width="400" height="300"  autoPlay playsInline></video>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			async openShare(e){
				try{
					var mediaOpts = {
						  video: true
					}
					const stream = await navigator.mediaDevices.getDisplayMedia(mediaOpts);
					console.log('success');
					this.handleSuccess(stream);
		
				}catch(e){
					this.handleError(e);
				}
			},
				handleSuccess(stream){
			        //const video = this.refs['myVideo'];
					const video = document.querySelector('video');
					const videoTracks = stream.getVideoTracks();
					console.log('使用的设备是:' + videoTracks[0].label);
			        window.stream = stream;
			        video.srcObject = stream;
			    },
			
			    handleError(error){
			        console.log(error);
			    }
		}
	}
</script>

<style>

</style>
